#!/bin/bash
# Script for building the Judge0 API.
# Builds both production and development image.
#
# Usage: ./scripts/dev/build
#
# If you want to use another image as a build cache,
# then use CACHE_FROM variable:
#
# CACHE_FROM=judge0/api:1.5.0 ./scripts/dev/build
#
set -xe

image=judge0/api
commit_hash="$(git log -1 --format=%h --abbrev=8)"
prod_image=$image:$commit_hash
dev_image=$image:$commit_hash-dev

cache=""
if [[ -v CACHE_FROM ]]; then
    docker pull $CACHE_FROM
    cache="--cache-from $CACHE_FROM"
fi

docker build -t $prod_image $cache --target production .
docker build -t $dev_image $cache --target development .

echo $prod_image
echo $dev_image
